package com.dunqi.gpm.cangxi.WeekReport.WeekSet

import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.dunqi.gpm.cangxi.R
import com.dunqi.gpm.cangxi.WeekReport.Model.WeekPlan
import com.dunqi.gpm.cangxi.WeekReport.OnListFragmentInteractionListener

class MyItemWeekSetRecyclerViewAdapter(private val mValues: List<WeekPlan>, private val mListener: OnListFragmentInteractionListener?) : RecyclerView.Adapter<MyItemWeekSetRecyclerViewAdapter.ViewHolder>() {
    val myFlag = 1
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent.context)
                .inflate(R.layout.fragment_itemweekset, parent, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.mItem = mValues[position]
        val index = position + 1
        holder.project_name.text = "$index: 单位名称"
        holder.project_duty_units.text = "责任单位:"
        holder.project_implement_units.text = "施工单位:"
        holder.project_superversion_units.text = "监理单位:"

        holder.mView.setOnClickListener { v ->
            mListener?.onListFragmentInteraction(holder.mItem!!, myFlag)
        }
    }

    override fun getItemCount(): Int {
        return mValues.size
    }

    inner class ViewHolder(val mView: View) : RecyclerView.ViewHolder(mView) {
        val project_name: TextView//项目名称
        val project_duty_units: TextView//责任单位名称
        val project_implement_units: TextView//施工单位名称
        val project_superversion_units: TextView//监理单位名称
        var mItem: WeekPlan? = null

        init {
            project_name = mView.findViewById(R.id.project_name)
            project_duty_units = mView.findViewById(R.id.project_duty_units)
            project_implement_units = mView.findViewById(R.id.project_implement_units)
            project_superversion_units = mView.findViewById(R.id.project_superversion_units)
        }
    }
}
